cmake_minimum_required(VERSION 3.16)

set(CMAKE_C_COMPILER        /usr/bin/clang)
set(CMAKE_CXX_COMPILER        /usr/bin/clang++)


project(crypto_framework)

set(CMAKE_SYSTEM_NAME        Linux)
set(CMAKE_SYSTEM_PROCESSOR   x86)


set(SCF_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(DEPENF_DIR ${SCF_DIR}/lib)
set(INC_DIR ${SCF_DIR}/include)

list(APPEND OSSL_TEST_COMPILE_CFLAGS -O0 -g -Wno-c++11-narrowing -fsanitize=address -fsanitize-recover=all -fno-omit-frame-pointer -DOPENSSL_SUPPRESSS_DEPRECATED -DOPENSSL_NO_FILENAMES)
# list(APPEND OSSL_TEST_COMPILE_CFLAGS -O0 -g -Wno-c++11-narrowing -fsanitize=address -fsanitize-recover=all -fno-omit-frame-pointer --coverage -DOPENSSL_SUPPRESSS_DEPRECATED -DOPENSSL_NO_FILENAMES -fprofile-arcs -ftest-coverage)

add_library(test_compile_config INTERFACE)
target_compile_options(test_compile_config INTERFACE ${OSSL_TEST_COMPILE_CFLAGS})
add_library(test_link_config INTERFACE)
target_link_options(test_link_config INTERFACE -lasan -Wl -pthread)
# target_link_options(test_link_config INTERFACE -lasan -Wl, -lgcov -pthread --coverage)


set(CRYPTO_INCLUDE
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/key/sym_key_generator/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/key/asy_key_generator/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/cipher/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/hmac/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/kdf/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/key_agreement/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/md/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/rand/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/signature/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/common/inc/
    ${SCF_DIR}/security_crypto_framework/frameworks/spi/
    ${SCF_DIR}/security_crypto_framework/frameworks/native/include/
    ${SCF_DIR}/security_crypto_framework/interfaces/innerkits/algorithm_parameter/
    ${SCF_DIR}/security_crypto_framework/interfaces/innerkits/common/
    ${SCF_DIR}/security_crypto_framework/interfaces/innerkits/crypto_operation/
    ${SCF_DIR}/security_crypto_framework/interfaces/innerkits/key/
    ${SCF_DIR}/security_crypto_framework/interfaces/kits/native/include/
    ${SCF_DIR}/security_crypto_framework/common/inc/
    ${INC_DIR}/
)

set(plugin_path ${SCF_DIR}/security_crypto_framework/plugin)
set(common_path ${SCF_DIR}/security_crypto_framework/common)

set(PLUGIN_SIGNATURE_FILES
  ${plugin_path}/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/signature/src/ecdsa_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/signature/src/signature_rsa_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/signature/src/sm2_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/signature/src/ed25519_openssl.c
)

set(PLUGIN_COMMON_FILES
  ${plugin_path}/openssl_plugin/common/src/openssl_adapter.c
  ${plugin_path}/openssl_plugin/common/src/openssl_common.c
  ${plugin_path}/openssl_plugin/common/src/dh_openssl_common.c
  ${plugin_path}/openssl_plugin/common/src/ecc_openssl_common.c
  ${plugin_path}/openssl_plugin/common/src/rsa_openssl_common.c
)

set(PLUGIN_ASY_KEY_GENERATOR_FILES
  ${plugin_path}/openssl_plugin/key/asy_key_generator/src/dsa_asy_key_generator_openssl.c
  ${plugin_path}/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c
  ${plugin_path}/openssl_plugin/key/asy_key_generator/src/dh_asy_key_generator_openssl.c
  ${plugin_path}/openssl_plugin/key/asy_key_generator/src/dh_common_param_spec_generator_openssl.c
  ${plugin_path}/openssl_plugin/key/asy_key_generator/src/ecc_common_param_spec_generator_openssl.c
  ${plugin_path}/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c
  ${plugin_path}/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c
  ${plugin_path}/openssl_plugin/key/asy_key_generator/src/alg_25519_asy_key_generator_openssl.c
)

set(PLUGIN_KEY_AGREEMENT_FILES
  ${plugin_path}/openssl_plugin/crypto_operation/key_agreement/src/dh_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/key_agreement/src/ecdh_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/key_agreement/src/x25519_openssl.c
)

set(PLUGIN_SYM_KEY_FILES
  ${plugin_path}/openssl_plugin/key/sym_key_generator/src/sym_key_openssl.c
)

set(PLUGIN_CIPHER_FILES
  ${plugin_path}/openssl_plugin/crypto_operation/cipher/src/cipher_rsa_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/cipher/src/cipher_3des_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/cipher/src/cipher_aes_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/cipher/src/cipher_aes_common.c
  ${plugin_path}/openssl_plugin/crypto_operation/cipher/src/cipher_sm4_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/cipher/src/cipher_sm2_crypto_util_openssl.c
)

set(PLUGIN_HMAC_FILES
 ${plugin_path}/openssl_plugin/crypto_operation/hmac/src/mac_openssl.c )

set(PLUGIN_RAND_FILES
 ${plugin_path}/openssl_plugin/crypto_operation/rand/src/rand_openssl.c )

set(PLUGIN_MD_FILES
 ${plugin_path}/openssl_plugin/crypto_operation/md/src/md_openssl.c )

set(PLUGIN_KDF_FILES
  ${plugin_path}/openssl_plugin/crypto_operation/kdf/src/pbkdf2_openssl.c
  ${plugin_path}/openssl_plugin/crypto_operation/kdf/src/hkdf_openssl.c
)

set(COMMON_FILES
  ${common_path}/src/asy_key_params.c
  ${common_path}/src/blob.c
  ${common_path}/src/hcf_parcel.c
  ${common_path}/src/hcf_string.c
  ${common_path}/src/log.c
  ${common_path}/src/memory.c
  ${common_path}/src/object_base.c
  ${common_path}/src/params_parser.c
  ${common_path}/src/utils.c
)

file(GLOB_RECURSE OPENSSL_PLUGIN_SRC
    ${PLUGIN_ASY_KEY_GENERATOR_FILES}
    ${PLUGIN_KEY_AGREEMENT_FILES}
    ${PLUGIN_SYM_KEY_FILES}
    ${PLUGIN_CIPHER_FILES}
    ${PLUGIN_HMAC_FILES}
    ${PLUGIN_RAND_FILES}
    ${PLUGIN_MD_FILES}
    ${PLUGIN_SIGNATURE_FILES}
    ${PLUGIN_COMMON_FILES}
    ${PLUGIN_KDF_FILES}
)

file(GLOB_RECURSE COMMON_SRC
  ${COMMON_FILES}
)

file(GLOB_RECURSE CRYPTO_FRAMEWORK_SRC
    ${SCF_DIR}/security_crypto_framework/frameworks/crypto_operation/*
    ${SCF_DIR}/security_crypto_framework/frameworks/native/src/*
    ${SCF_DIR}/security_crypto_framework/frameworks/key/*
)

set(TDD_INC
    ${CRYPTO_INCLUDE}/
    ${SCF_DIR}/security_crypto_framework/common/inc/
    ${SCF_DIR}/security_crypto_framework/test/unittest/include/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/signature/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/key/asy_key_generator/inc/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/key/asy_key_generator/src/
    ${SCF_DIR}/security_crypto_framework/plugin/openssl_plugin/crypto_operation/signature/src/
)

file(GLOB_RECURSE TDD_SRC
    ${SCF_DIR}/security_crypto_framework/test/unittest/src/*.cpp
    ${SCF_DIR}/security_crypto_framework/test/unittest/src/*.c
    ${SCF_DIR}/security_crypto_framework/test/unittest/src/sm2/*.cpp
    ${SCF_DIR}/security_crypto_framework/test/unittest/src/ecc/*.cpp
    ${SCF_DIR}/security_crypto_framework/test/unittest/src/aes_cipher/*.cpp
    ${SCF_DIR}/security_crypto_framework/common/src/*
)
list(REMOVE_ITEM TDD_SRC ${SCF_DIR}/security_crypto_framework/common/src/memory.c)

add_library(openssl_plugin_obj OBJECT ${OPENSSL_PLUGIN_SRC})
target_compile_options(openssl_plugin_obj PRIVATE -fPIC)
target_include_directories(openssl_plugin_obj PRIVATE ${CRYPTO_INCLUDE})
target_link_libraries(openssl_plugin_obj test_compile_config)

add_library(openssl_plugin OBJECT SHARED $<TARGET_OBJECTS:openssl_plugin_obj>)
target_link_directories(openssl_plugin PRIVATE ${DEPENF_DIR})
target_link_libraries(openssl_plugin test_link_config  crypto boundscheck)

add_library(crypto_framework_obj OBJECT ${CRYPTO_FRAMEWORK_SRC})
target_compile_options(crypto_framework_obj PRIVATE -fPIC)
target_include_directories(crypto_framework_obj PRIVATE ${CRYPTO_INCLUDE})
target_link_libraries(crypto_framework_obj test_compile_config)

add_library(crypto_framework OBJECT SHARED $<TARGET_OBJECTS:crypto_framework_obj>)
target_link_directories(crypto_framework PRIVATE ${DEPENF_DIR})
target_link_libraries(crypto_framework test_link_config  libcrypto.a boundscheck)

add_library(common_obj OBJECT ${COMMON_SRC})
target_compile_options(common_obj PRIVATE -fPIC)
target_include_directories(common_obj PRIVATE ${CRYPTO_INCLUDE})
target_link_libraries(common_obj test_compile_config)

add_library(common OBJECT SHARED $<TARGET_OBJECTS:common_obj>)
target_link_directories(common PRIVATE ${DEPENF_DIR})
target_link_libraries(common test_link_config  crypto boundscheck)

add_library(tdd_obj OBJECT ${TDD_SRC})
target_compile_options(tdd_obj PRIVATE -DINT_MAX=1000 -Wno-narrowing)
target_include_directories(tdd_obj PRIVATE ${TDD_INC})
target_link_libraries(tdd_obj test_compile_config)

add_executable(tdd $<TARGET_OBJECTS:tdd_obj>)
target_link_directories(tdd PRIVATE ${DEPENF_DIR} ${SCF_DIR}/build)
target_link_libraries(tdd test_link_config  -lcrypto_framework -lopenssl_plugin crypto boundscheck gtest gtest_main gmock)

add_dependencies(tdd openssl_plugin crypto_framework)

# ASAN_OPTIONS=detect_stack_use_after_return=1;strict_string_checks=1:detect_leaks=1:halt_on_error=0:log_path=asan.log

set(DEP_INCLUDE
    ${SCF_DIR}/security_crypto_framework/interfaces/innerkits/common/
    ${SCF_DIR}/security_crypto_framework/interfaces/innerkits/key/
    ${SCF_DIR}/security_crypto_framework/interfaces/innerkits/algorithm_parameter/
    ${SCF_DIR}/security_crypto_framework/interfaces/innerkits/crypto_operation/
    ${INC_DIR}/
)

set(sec_cert_framework_comm_inc
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/certificate/
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/common/
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/include/
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/inc/
)

set(sec_cert_framework_comm_src
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/cf_blob.c
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/utils.c
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/cf_memory.c
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/cf_object_base.c
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/cf_check.c
)

set(sec_cert_framework_cap_inc
    ${SCF_DIR}/security_certificate_framework/frameworks/ability/inc/
)

set(sec_cert_framework_cap_src
    ${SCF_DIR}/security_certificate_framework/frameworks/ability/src/cf_ability.c
)

set(sec_cert_framework_adp_v1_0_inc
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/inc/
)

set(sec_cert_framework_adp_v1_0_src
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/certificate_openssl_common.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_cert_chain_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_cert_chain_openssl_ex.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_cert_chain_validator_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_certificate_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_crl_entry_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_crl_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_distinguished_name_openssl.c
)

set(sec_cert_framework_adp_v2_0_inc
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v2.0/inc/
)

set(sec_cert_framework_adp_v2_0_src
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v2.0/src/cf_adapter_ability.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v2.0/src/cf_adapter_cert_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v2.0/src/cf_adapter_extension_openssl.c
)

set(sec_cert_framework_core_inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/cert/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/extension/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/life/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/param/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/spi
)

set(sec_cert_framework_core_src
    ${SCF_DIR}/security_certificate_framework/frameworks/core/cert/src/cf_cert_ability.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/cert/src/cf_object_cert.c
    
    ${SCF_DIR}/security_certificate_framework/frameworks/core/extension/src/cf_extension_ability.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/extension/src/cf_object_extension.c
    
    ${SCF_DIR}/security_certificate_framework/frameworks/core/life/cf_api.c
    
    ${SCF_DIR}/security_certificate_framework/frameworks/core/param/src/cf_param.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/param/src/cf_param_parse.c
    
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/cert_chain_validator.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/cert_crl_collection.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/cert_crl_common.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/x509_cert_chain.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/x509_certificate.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/x509_crl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/x509_distinguished_name.c
)

set(target_sec_cert_frame_core certificate_framework_core.z)

add_library(sec_cert_core_obj OBJECT 
    ${sec_cert_framework_core_src}
    ${sec_cert_framework_adp_v1_0_src}
    ${sec_cert_framework_adp_v2_0_src}
)
target_compile_options(sec_cert_core_obj PRIVATE -fPIC)
target_include_directories(sec_cert_core_obj PRIVATE 
    ${DEP_INCLUDE}
    ${sec_cert_framework_comm_inc}
    ${sec_cert_framework_core_inc}
    ${sec_cert_framework_adp_v1_0_inc}
    ${sec_cert_framework_adp_v2_0_inc}
    ${sec_cert_framework_cap_inc}
)
target_link_libraries(sec_cert_core_obj
    test_compile_config
)

add_library(${target_sec_cert_frame_core} SHARED
    $<TARGET_OBJECTS:sec_cert_core_obj>    
)

target_link_directories(${target_sec_cert_frame_core} PRIVATE 
    ${DEPENF_DIR}
)

target_link_libraries(${target_sec_cert_frame_core}
    test_link_config crypto ssl boundscheck asan)

set(target_sec_cert cert.z)

add_library(sec_cert_obj OBJECT 
    ${sec_cert_framework_comm_src}
    ${sec_cert_framework_cap_src}
)

target_compile_options(sec_cert_obj PRIVATE -fPIC)
target_include_directories(sec_cert_obj PRIVATE 
    ${DEP_INCLUDE}
    ${sec_cert_framework_comm_inc}
    ${sec_cert_framework_cap_inc}
)
target_link_libraries(sec_cert_obj
    test_compile_config
)

add_library(${target_sec_cert} SHARED
    $<TARGET_OBJECTS:sec_cert_obj>    
)

target_link_directories(${target_sec_cert} PRIVATE 
    ${DEPENF_DIR}
)

target_link_libraries(${target_sec_cert}
    test_link_config crypto ssl boundscheck asan)

# For cf adapter test
set(cf_adapter_test_inc
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/include
    ${SCF_DIR}/security_certificate_framework/frameworks/core/cert/inc
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/include/
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/common/
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/include
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/spi
    ${sec_cert_framework_cap_inc}
    ${sec_cert_framework_comm_inc}
    ${sec_cert_framework_adp_v2_0_inc}
    ${DEP_INCLUDE}
)

set(cf_adapter_test_src
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/src/cf_test_common.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_adapter_test/src/cf_ability_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_adapter_test/src/cf_adapter_cert_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_adapter_test/src/cf_adapter_extension_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_adapter_test/src/cf_common_test.cpp
)

add_executable(cf_adapter_test ${cf_adapter_test_src})
target_include_directories(cf_adapter_test PRIVATE ${cf_adapter_test_inc})
target_link_directories(cf_adapter_test PRIVATE ${DEPENF_DIR} ${DEPENF_DIR})
target_link_libraries(cf_adapter_test 
    test_compile_config test_link_config certificate_framework_core.z cert.z gtest gtest_main asan )

# For cf core test
set(cf_core_test_inc
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/include
    ${SCF_DIR}/security_certificate_framework/frameworks/core/cert/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/extension/inc
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/include/
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/common/
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/include
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/spi
    ${sec_cert_framework_cap_inc}
    ${sec_cert_framework_comm_inc}
    ${sec_cert_framework_adp_v2_0_inc}
    ${DEP_INCLUDE}
)

set(cf_core_test_src
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_core_test/src/cf_object_cert_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_core_test/src/cf_object_extension_test.cpp
)

add_executable(cf_core_test ${cf_core_test_src})
target_include_directories(cf_core_test PRIVATE ${cf_core_test_inc})
target_link_directories(cf_core_test PRIVATE ${DEPENF_DIR} ${DEPENF_DIR})
target_link_libraries(cf_core_test 
    test_compile_config test_link_config
    certificate_framework_core.z cert.z gtest crypto gtest_main asan)


# For cf sdk test
set(cf_sdk_test_inc
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/include/
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_sdk_test/include/
    ${SCF_DIR}/security_certificate_framework/frameworks/core/cert/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/extension/inc
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/include/
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/common/
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/include
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/spi
    ${DEP_INCLUDE}
)

set(cf_sdk_test_src
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/src/cf_test_common.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/src/cf_test_sdk_common.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_sdk_test/src/cf_cert_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_sdk_test/src/cf_extension_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_sdk_test/src/cf_param_test.cpp
)

add_executable(cf_sdk_test ${cf_sdk_test_src})
target_include_directories(cf_sdk_test PRIVATE ${cf_sdk_test_inc})
target_link_directories(cf_sdk_test PRIVATE ${DEPENF_DIR} ${DEPENF_DIR})
target_link_libraries(cf_sdk_test 
    test_compile_config test_link_config
    certificate_framework_core.z cert.z gtest gtest_main asan)


# For cf 1.0 test
set(cf_1_0_test_inc
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/include/
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_sdk_test/include/
    ${SCF_DIR}/security_certificate_framework/frameworks/core/extension/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/cert/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/inc
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/spi
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/include/
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/common/
    ${SCF_DIR}/security_certificate_framework/interfaces/innerkits/certificate
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/include
    ${DEP_INCLUDE}
)

set(cf_1_0_test_src
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/src/cf_test_common.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/common/src/cf_test_sdk_common.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_sdk_test/src/cf_cert_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_sdk_test/src/cf_extension_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/cf_sdk_test/src/cf_param_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/cf_mock.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_cert_chain_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_cert_chain_test_ex.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_cert_chain_test_part2.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_cert_chain_validator_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_cert_crl_collection_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_certificate_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_certificate_test_part2.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_certificate_test_part3.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_crl_test.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_crl_test_part2.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/crypto_x509_test_common.cpp
    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/x509_distinguished_name_test.cpp

    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/cert_chain_validator.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/cert_crl_collection.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/cert_crl_common.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/x509_cert_chain.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/x509_certificate.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/x509_crl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/core/v1.0/certificate/x509_distinguished_name.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/certificate_openssl_common.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_cert_chain_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_cert_chain_openssl_ex.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_cert_chain_validator_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_certificate_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_crl_entry_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_crl_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/adapter/v1.0/src/x509_distinguished_name_openssl.c
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/cf_blob.c
    # ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/cf_log.c
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/cf_object_base.c
    ${SCF_DIR}/security_certificate_framework/frameworks/common/v1.0/src/utils.c

    ${SCF_DIR}/security_certificate_framework/test/unittest/v1.0/src/memory_mock.c
)

add_executable(cf_1_0_test ${cf_1_0_test_src})
target_include_directories(cf_1_0_test PRIVATE ${cf_1_0_test_inc} ${TDD_INC})
target_link_directories(cf_1_0_test PRIVATE ${DEPENF_DIR} ${SCF_DIR}/build)
# target_link_directories(cf_1_0_test PRIVATE ${DEPENF_DIR})
target_link_libraries(cf_1_0_test 
    test_compile_config test_link_config -lcrypto_framework -lopenssl_plugin -lcommon
    certificate_framework_core.z cert.z gtest gtest_main gmock asan)

target_link_options(cf_1_0_test PRIVATE
    -Wl,-E
    -Wl,--wrap=i2d_X509_EXTENSIONS
    -Wl,--wrap=OPENSSL_sk_num
    -Wl,--wrap=X509_getm_notBefore
    -Wl,--wrap=X509_getm_notAfter
    -Wl,--wrap=X509_NAME_oneline
    -Wl,--wrap=i2d_X509
    -Wl,--wrap=BIO_new_mem_buf
    -Wl,--wrap=OPENSSL_sk_value
    -Wl,--wrap=HcfX509CertificateCreate
    -Wl,--wrap=OPENSSL_sk_new_null
    -Wl,--wrap=X509_STORE_add_cert
    -Wl,--wrap=X509_STORE_CTX_new
    -Wl,--wrap=X509_STORE_new
    -Wl,--wrap=X509_STORE_CTX_init
    -Wl,--wrap=X509_verify_cert
    -Wl,--wrap=i2d_PUBKEY
    -Wl,--wrap=X509_get_ext_d2i
    -Wl,--wrap=i2d_ASN1_OCTET_STRING
    -Wl,--wrap=i2d_AUTHORITY_KEYID
    -Wl,--wrap=DeepCopyDataToBlob
    -Wl,--wrap=ASN1_TIME_new
    -Wl,--wrap=X509_get0_serialNumber
    -Wl,--wrap=i2d_ASN1_INTEGER
    -Wl,--wrap=X509_get_pubkey
    -Wl,--wrap=OBJ_nid2obj
    -Wl,--wrap=OBJ_obj2txt
    -Wl,--wrap=BN_bin2bn
    -Wl,--wrap=ASN1_TIME_normalize
    -Wl,--wrap=X509_ALGOR_get0
    -Wl,--wrap=ASN1_TYPE_new
    -Wl,--wrap=ASN1_TYPE_set1
    -Wl,--wrap=i2d_ASN1_TYPE
    -Wl,--wrap=ASN1_INTEGER_get
    -Wl,--wrap=ASN1_STRING_get0_data
    -Wl,--wrap=i2d_GENERAL_NAME
    -Wl,--wrap=X509_get_ext
    -Wl,--wrap=X509V3_EXT_d2i
    -Wl,--wrap=GENERAL_NAME_get0_value
    -Wl,--wrap=X509_verify
    -Wl,--wrap=DeepCopyBlobToBlob
    -Wl,--wrap=OPENSSL_sk_push
    -Wl,--wrap=i2d_X509_REVOKED
    -Wl,--wrap=i2d_X509_CRL
    -Wl,--wrap=OPENSSL_sk_deep_copy
    -Wl,--wrap=OBJ_obj2nid
    -Wl,--wrap=X509_dup
    -Wl,--wrap=X509_check_host
    -Wl,--wrap=OCSP_REQUEST_new
    -Wl,--wrap=X509_CRL_load_http
    -Wl,--wrap=X509_get1_ocsp
    -Wl,--wrap=OSSL_HTTP_parse_url
    -Wl,--wrap=X509_NAME_get0_der
    -Wl,--wrap=OBJ_nid2sn
    -Wl,--wrap=ASN1_STRING_length
    -Wl,--wrap=DeepCopyDataToOut
    -Wl,--wrap=CRYPTO_strdup
    -Wl,--wrap=X509_NAME_new
    -Wl,--wrap=OBJ_txt2nid
    -Wl,--wrap=X509_NAME_add_entry_by_NID
    -Wl,--wrap=BIO_new
    -Wl,--wrap=X509_print
    -Wl,--wrap=BIO_ctrl
    -Wl,--wrap=i2d_X509_bio
    -Wl,--wrap=PKCS12_parse
    -Wl,--wrap=CheckIsSelfSigned
)
